/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.entity;

import br.com.foxline.clinicplus.enums.PaymentType;
import br.com.foxline.clinicplus.enums.TypeCredit;
import br.com.foxline.clinicplus.enums.TypeDebt;
import br.com.foxline.clinicplus.enums.TypeIncome;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;

/**
 *
 * @author roniere
 */
@Entity
public class Income implements Serializable{
    
    @Id
    @SequenceGenerator(sequenceName = "seq_income", name = "seq_income", allocationSize = 1)
    @GeneratedValue(generator = "seq_income", strategy = GenerationType.SEQUENCE)
    private Long id;
    
    @OneToOne
    private Diary diary;
    
    @ManyToOne
    private SystemUser systemUser;
    
    /**
     * Data que o income foi criado
     */
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date createAt;
    
    @ManyToOne
    private Doctor doctor;
    
    @ManyToOne
    private Procedure procedure;
    
    //VALOR BRUTO
    @Column(scale= 4, precision=10)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal amount;
    
    //DESCONTO
    @Column(scale= 4, precision=10)
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal discount;
    
    //VALOR PAGO
    @Column(scale= 4, precision=10)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal amountPaid;
    
    //VALOR TOTAL
    @Column(scale= 4, precision=10)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal totalAmount;
    
    //VALOR CARTÃO
    @Column(scale= 4, precision=10)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal amountCard;
    
    //VALOR DINHEIRO
    @Column(scale= 4, precision=10)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 4, integer = 10 )
    private BigDecimal amountMoney;
    
    @Enumerated(EnumType.STRING)
    private PaymentType paymentType;
    
    //SAÍDA
    private String descricao; 
    
    @Enumerated(EnumType.STRING)
    private TypeIncome typeIncome;

    @Enumerated(EnumType.STRING)
    private TypeDebt typeDebt;
    
    @Enumerated(EnumType.STRING)
    private TypeCredit typeCredit;
    
    @Version
    private int version;
    
    
    private boolean permissionEditAdmin;
    
    private boolean ativo;
    
    //compensacao do plano
    private boolean compensado;
    /**
     * Data em que o income foi compensado
     */
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dataCompensacao;
    @ManyToOne
    private SystemUser responsavelCompensacao;
    
    //Controle de entradas de convênio
    private boolean faturamentoImediato;
    
    @ManyToOne
    private Cash cash;

    public Income() {
        this.setAtivo(true);
    }

    public Cash getCash() {
        return cash;
    }

    public void setCash(Cash cash) {
        this.cash = cash;
    }

    
    public boolean isFaturamentoImediato() {
        return faturamentoImediato;
    }

    public void setFaturamentoImediato(boolean faturamentoImediato) {
        this.faturamentoImediato = faturamentoImediato;
    }
    
    
    

    public boolean isCompensado() {
        return compensado;
    }

    public void setCompensado(boolean compensado) {
        this.compensado = compensado;
    }

    public Date getDataCompensacao() {
        return dataCompensacao;
    }

    public void setDataCompensacao(Date dataCompensacao) {
        this.dataCompensacao = dataCompensacao;
    }

    public SystemUser getResponsavelCompensacao() {
        return responsavelCompensacao;
    }

    public void setResponsavelCompensacao(SystemUser responsavelCompensacao) {
        this.responsavelCompensacao = responsavelCompensacao;
    }
    
    public boolean isAtivo() {
        return ativo;
    }

    public void setAtivo(boolean ativo) {
        this.ativo = ativo;
    }

    
    public TypeCredit getTypeCredit() {
        return typeCredit;
    }

    public void setTypeCredit(TypeCredit typeCredit) {
        this.typeCredit = typeCredit;
    }

    
    public BigDecimal getAmountCard() {
        return amountCard;
    }

    public void setAmountCard(BigDecimal amountCard) {
        this.amountCard = amountCard;
    }

    public BigDecimal getAmountMoney() {
        return amountMoney;
    }

    public void setAmountMoney(BigDecimal amountMoney) {
        this.amountMoney = amountMoney;
    }

    
    public boolean isPermissionEditAdmin() {
        return permissionEditAdmin;
    }

    public void setPermissionEditAdmin(boolean permissionEditAdmin) {
        this.permissionEditAdmin = permissionEditAdmin;
    }
    
    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }
    
    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public TypeDebt getTypeDebt() {
        return typeDebt;
    }

    public void setTypeDebt(TypeDebt typeDebt) {
        this.typeDebt = typeDebt;
    }
    
    
    
    public TypeIncome getTypeIncome() {
        return typeIncome;
    }

    public void setTypeIncome(TypeIncome typeIncome) {
        this.typeIncome = typeIncome;
    }
    
    public BigDecimal getAmount() {
        return amount;
    }

    public BigDecimal getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(BigDecimal amountPaid) {
        this.amountPaid = amountPaid;
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    public void setDiscount(BigDecimal discount) {
        this.discount = discount;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public Diary getDiary() {
        return diary;
    }

    public void setDiary(Diary diary) {
        this.diary = diary;
    }

    public Doctor getDoctor() {
        return doctor;
    }

    public void setDoctor(Doctor doctor) {
        this.doctor = doctor;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public Procedure getProcedure() {
        return procedure;
    }

    public void setProcedure(Procedure procedure) {
        this.procedure = procedure;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Income other = (Income) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.diary != other.diary && (this.diary == null || !this.diary.equals(other.diary))) {
            return false;
        }
        if (this.systemUser != other.systemUser && (this.systemUser == null || !this.systemUser.equals(other.systemUser))) {
            return false;
        }
        if (this.createAt != other.createAt && (this.createAt == null || !this.createAt.equals(other.createAt))) {
            return false;
        }
        if (this.doctor != other.doctor && (this.doctor == null || !this.doctor.equals(other.doctor))) {
            return false;
        }
        if (this.procedure != other.procedure && (this.procedure == null || !this.procedure.equals(other.procedure))) {
            return false;
        }
        
        if (this.amount != other.amount && (this.amount == null || !this.amount.equals(other.amount))) {
            return false;
        }
        if (this.discount != other.discount && (this.discount == null || !this.discount.equals(other.discount))) {
            return false;
        }
        if (this.amountPaid != other.amountPaid && (this.amountPaid == null || !this.amountPaid.equals(other.amountPaid))) {
            return false;
        }
        if (this.totalAmount != other.totalAmount && (this.totalAmount == null || !this.totalAmount.equals(other.totalAmount))) {
            return false;
        }
        if (this.paymentType != other.paymentType) {
            return false;
        }
        if (this.typeIncome != other.typeIncome) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 43 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 43 * hash + (this.diary != null ? this.diary.hashCode() : 0);
        hash = 43 * hash + (this.systemUser != null ? this.systemUser.hashCode() : 0);
        hash = 43 * hash + (this.createAt != null ? this.createAt.hashCode() : 0);
        hash = 43 * hash + (this.doctor != null ? this.doctor.hashCode() : 0);
        hash = 43 * hash + (this.procedure != null ? this.procedure.hashCode() : 0);
        hash = 43 * hash + (this.amount != null ? this.amount.hashCode() : 0);
        hash = 43 * hash + (this.discount != null ? this.discount.hashCode() : 0);
        hash = 43 * hash + (this.amountPaid != null ? this.amountPaid.hashCode() : 0);
        hash = 43 * hash + (this.totalAmount != null ? this.totalAmount.hashCode() : 0);
        hash = 43 * hash + (this.paymentType != null ? this.paymentType.hashCode() : 0);
        hash = 43 * hash + (this.typeIncome != null ? this.typeIncome.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Income{" + "id=" + id + ", diary=" + diary + ", systemUser=" + systemUser + ", createAt=" + createAt + ", doctor=" + doctor + ", procedure=" + procedure + ", amount=" + amount + ", discount=" + discount + ", amountPaid=" + amountPaid + ", totalAmount=" + totalAmount + ", amountCard=" + amountCard + ", amountMoney=" + amountMoney + ", paymentType=" + paymentType + ", descricao=" + descricao + ", typeIncome=" + typeIncome + ", typeDebt=" + typeDebt + ", typeCredit=" + typeCredit + ", version=" + version + ", permissionEditAdmin=" + permissionEditAdmin + ", ativo=" + ativo + ", compensado=" + compensado + ", dataCompensacao=" + dataCompensacao + ", responsavelCompensacao=" + responsavelCompensacao + ", faturamentoImediato=" + faturamentoImediato + '}';
    }

    
    
            
}
